package com.skyline.base.dao.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import com.skyline.base.dao.SiteDao;
import com.skyline.base.mapper.SiteMapper;
import com.skyline.base.model.Site;


/**
 * 地点模块的Dao实现
 * 
 * @author Jairus Chan
 * @version 0.1
 * */
@Repository("siteDao")
public class SiteDaoImpl implements SiteDao {
	@Autowired
	protected JdbcTemplate jdbcTemplate;

	/**
	 * select * from site
	 * */
	@Value("${SiteDao.queryAllSites}")
	private String queryAllSitesSql;

	/**
	 * select * from site where parent=?
	 * */
	@Value("${SiteDao.querySubSites}")
	private String querySubSitesSql;

	/**
	 * select * from site where id=?
	 * */
	@Value("${SiteDao.queryParentSite}")
	private String queryParentSiteSql;

	/**
	 * select * from site where type='nation'
	 * */
	@Value("${SiteDao.queryAllNations}")
	private String queryAllNationsSql;

	@Override
	public List<Site> queryAllSites() {
		return jdbcTemplate.query(queryAllSitesSql, SiteMapper.getMapper());
	}

	@Override
	public List<Site> querySubSites(String siteID) {
		return jdbcTemplate.query(querySubSitesSql, SiteMapper.getMapper(), siteID);
	}

	@Override
	public Site querySiteByID(String siteID) {
		return jdbcTemplate.queryForObject(queryParentSiteSql, SiteMapper.getMapper(), siteID);
	}

	@Override
	public List<Site> queryDetailLocation(String siteID) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public List<Site> queryAllNations() {
		return jdbcTemplate.query(queryAllNationsSql, SiteMapper.getMapper());
	}

}
